package com.wang.config;

import com.wang.service.MyService;
import com.wang.service.MyServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * @Classname CxfConfig
 * @Description TODO
 * @Date 2024/5/31 11:48
 * @Created by pc
 */
@Configuration
public class CxfConfig {

    // 向ioc容器中注册servlet
    @Bean
    public ServletRegistrationBean createServletRegistrationBean(){
        return new ServletRegistrationBean(new CXFServlet(),"/myService/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus(){
        return new SpringBus();
    }

    // 注册自定义MyService接口
    @Bean
    public MyService myService(){
        return new MyServiceImpl();
    }

    // 注册端点服务
    @Bean
    public Endpoint endpoint(){
        Endpoint endpoint = new EndpointImpl(springBus(), myService());
        endpoint.publish("/api");
        return endpoint;
    }
}
